﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace bytes与struct的序列化
{
    /// <summary>
    /// 充值机协议
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct TopUPMachineProtocol
    {
        /// <summary>
        /// 帧头
        /// </summary>
        public byte frameHeader;
        /// <summary>
        /// 电脑MAC地址
        /// </summary>
        //int数组，SizeConst表示数组的个数，在转换成
        //byte数组前必须先初始化数组，再使用，初始化
        //的数组长度必须和SizeConst一致，例test = new int[6];
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
        public byte[] computerMacAddr;
        /// <summary>
        /// 机器MAC地址
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
        public byte[] machineMacAddr;
        /// <summary>
        /// 设备类型
        /// </summary>
        public byte machineType;
        /// <summary>
        /// 源机器号，即这些指令从哪台机器发出
        /// </summary>
        public UInt16 sourceMachineNum;
        /// <summary>
        /// 指令标志
        /// </summary>
        public byte CmdFlag;
        /// <summary>
        /// 数据长度
        /// </summary>
        public UInt16 dataLen;
        /// <summary>
        /// 目标机器号，即这些指令需要发往哪台机器
        /// </summary>
        public UInt16 targetMachineNum;
        /// <summary>
        /// 系统时间
        /// </summary>
        public UInt32 systemTime;
        /// <summary>
        /// 心跳时间间隔
        /// </summary>
        public UInt16 heartbeatInterval;
        /// <summary>
        /// 心跳应答延时
        /// </summary>
        public UInt16 heartbeatAckDly;
        /// <summary>
        /// 加校验
        /// </summary>
        public byte addCRC;
        /// <summary>
        /// 异或校验
        /// </summary>
        public byte exclusiveOrCRC;
        /// <summary>
        /// 帧尾
        /// </summary>
        public byte frameTail;

        //字符串，SizeConst为字符串的最大长度
        //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
        //public string str;
    }
}
